cmake_minimum_required(VERSION 3.5)

project(qt_keyboard VERSION 1.0)

set(CMAKE_AUTOMOC ON)  # 自动处理 Q_OBJECT 宏
set(CMAKE_AUTORCC ON)  # 自动处理资源文件
set(CMAKE_AUTOUIC ON)  # 自动处理UI文件（如有）

find_package(Qt5 REQUIRED COMPONENTS Widgets)

# 添加宏定义
add_definitions(-DENABLED_CHINESE_LIB -DENABLED_CHINESE_PHRASE_LIB -DENABLED_GOOGLE_CHINESE_LIB)

# 库的源文件（不包含main.cpp）
set(LIB_SOURCES
    Keyboard/KeyButton.cpp
    Keyboard/Keyboard.cpp
    Keyboard/NumberKeyboard.cpp
)

# 库的头文件
set(LIB_HEADERS
    Keyboard/AbstractKeyboard.h
    Keyboard/KeyButton.h
    Keyboard/Keyboard.h
    Keyboard/NumberKeyboard.h
    Keyboard/KeyboardManager.h
)

# 资源文件
qt5_add_resources(QT_RESOURCES
    Resources/Image.qrc
    Resources/ChineseLib.qrc
    Resources/ChinesePhraseLib.qrc
    Resources/GoogleChineseLib.qrc
    Resources/Font.qrc
)

# 创建动态库
add_library(qt_keyboard SHARED ${LIB_SOURCES} ${LIB_HEADERS} ${QT_RESOURCES})

# 设置动态库属性
set_target_properties(qt_keyboard PROPERTIES
    VERSION ${PROJECT_VERSION}
    SOVERSION 1
    CXX_STANDARD 11
    CXX_STANDARD_REQUIRED ON
)

# 添加头文件搜索路径
target_include_directories(qt_keyboard PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/Keyboard
)

# 链接Qt库
target_link_libraries(qt_keyboard PUBLIC Qt5::Widgets)

# 创建可执行文件
add_executable(qt_keyboard_test main.cpp)

# 链接动态库
target_link_libraries(qt_keyboard_test qt_keyboard)